import {
    setStore,
    getStore,
    removeStore
} from '@/util/store'
import website from '@/config/website'
const common = {

    state: {
        language: getStore({ name: 'language' }) || 'en',
        isCollapse: false,
        isFullScren: false,
        isShade: false,
        screen: -1,
        isLock: false,
        isRefresh: false,
        showTag: true,
        showMsg: true,
        showDebug: getStore({ name: 'showDebug' }) || true,
        showCollapse: getStore({ name: 'showCollapse' } || true),
        showSearch: false,
        showLock: false,
        showFullScren: getStore({ name: 'showFullScren' }) || true,
        showTheme: getStore({ name: 'showTheme' }) || true,
        showMenu: true,
        showColor: getStore({ name: 'showColor' }) || true,
        colorName: getStore({ name: 'colorName' }) || '#4285F4',
        themeName: getStore({ name: 'themeName' }) || 'theme-blue',
        lockPasswd: getStore({ name: 'lockPasswd' }) || '',
        website: website,
        msgsLen: getStore({ name: 'msgsLen' }) || 0,
    },
  actions: {},
    mutations: {
        SET_LANGUAGE: (state, language) => {
            state.language = language
            setStore({
                name: 'language',
                content: state.language
            })
        },
        SET_SHADE: (state, active) => {
            state.isShade = active;
        },
        SET_COLLAPSE: (state) => {
            state.isCollapse = !state.isCollapse;
        },
        SET_FULLSCREN: (state) => {
            state.isFullScren = !state.isFullScren;
        },
        SET_SHOWFULLSCREN: (state, active) => {
            state.showFullScren = active
            setStore({
                name: 'showFullScren',
                content: state.showFullScren
            })
        },
        SET_SHOWCOLLAPSE: (state, active) => {
            state.showCollapse = active
            setStore({
                name: 'showCollapse',
                content: state.showCollapse
            })
        },
        SET_REFRESH: (state) => {
            state.isRefresh = !state.isRefresh;            
        },     
        SET_SHOWDEBUG: (state, active) => {
            state.showDebug = active
            setStore({
                name: 'showDebug',
                content: state.showDebug
            })
        },   
        SET_SHOWTHEME: (state, active) => {
            state.showTheme = active
            setStore({
                name: 'showTheme',
                content: state.showTheme
            })
        },
        SET_SHOWCOLOR: (state, active) => {
            state.showColor = active
            setStore({
                name: 'showColor',
                content: state.showColor
            })
        },
        SET_LOCK: (state) => {
            state.isLock = true;
            setStore({
                name: 'isLock',
                content: state.isLock,
                type: 'session'
            })
        },
        SET_SCREEN: (state, screen) => {
            state.screen = screen;
        },
        SET_COLOR_NAME: (state, colorName) => {
            state.colorName = colorName;
            setStore({
                name: 'colorName',
                content: state.colorName,
            })
        },
        SET_THEME_NAME: (state, themeName) => {
            state.themeName = themeName;
            setStore({
                name: 'themeName',
                content: state.themeName,
            })
        },
        SET_LOCK_PASSWD: (state, lockPasswd) => {
            state.lockPasswd = lockPasswd;
            setStore({
                name: 'lockPasswd',
                content: state.lockPasswd,
                type: 'session'
            })
        },
        CLEAR_LOCK: (state) => {
          state.isLock = false;
          state.lockPasswd = '';
          removeStore({
              name: 'lockPasswd',
              type: 'session'
          });
          removeStore({
              name: 'isLock',
              type: 'session'
          });
        },
        SET_OBJ: function (state, { key, obj }) {
          obj = JSON.stringify(obj);
          localStorage.setItem(key, obj);
        },
        GET_OBJ: function (state, key) {
          var obj = JSON.parse(localStorage.getItem(key));
          return obj;
        },
    }
}
export default common